package com.liuxu.topnews.utils;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

import com.liuxu.topnews.MyApplication;

public class ToastUtils {
    private static ToastUtils Instance;
    private Context context;
    private Toast toast;
    public static ToastUtils getInstance() {
        if (Instance == null) {
            Instance = new ToastUtils();
        }
        return Instance;
    }
    public ToastUtils(){
        context=MyApplication.getContext();
        toast=Toast.makeText(context,"初始化",Toast.LENGTH_SHORT);
    }
    public void shownow(final String text){
        Handler handlerThree=new Handler(
                Looper.getMainLooper());
        handlerThree.post(new Runnable(){
            public void run(){
            toast.setText(text);
            toast.show();
            }
        });
    }
    public void show(final String text){
        Handler handlerThree=new Handler(
                Looper.getMainLooper());
        handlerThree.post(new Runnable(){
            public void run(){
        Toast.makeText(MyApplication.getContext(),text,Toast.LENGTH_SHORT).show();
            }
        });
    }
    public void showtoast(final String text, final boolean now){
        Handler handlerThree=new Handler(
                Looper.getMainLooper());
        handlerThree.post(new Runnable(){
            public void run(){
                if (now) {
                    toast.setText(text);
                    toast.show();
                } else {
                    Toast.makeText(MyApplication.getContext(),text,Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
